import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;

// 页面内容 左侧树
export function getPage() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getListAllInstitutions',
    method: 'post',
    data: data
  })
}
// export function getPage(queryParams) {
//     const data = {
//       ascriptionId: store.state.userInfo.ascriptionId,
//       currentPage: queryParams.currentPage,
//       pagesize: queryParams.pagesize
//     }
//     return request({
//       url: '/getOutsourcingPage',
//       method: 'post',
//       data: data
//     })
// }

// 数据列表
// workType 工种id 多个逗号隔开
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    unitId: queryParams.unitId, //工作单位id
    workType: queryParams.workType, //工种id
    keywords: queryParams.keywords
  }
  return request({
    url: '/getOutsourcingList',
    method: 'post',
    data: data
  })
}


//  新增
export function addData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId, //机构 id
      fullName: val.fullName, //姓名
      password: val.password, //登录密码
      headPortrait: val.headPortrait, //头像照片
      genderId: val.genderId, //性别 id 1-男 2-女
      genderVal: val.genderVal, //性别的文字值
      unitId: val.unitId, //工作单位 id
      workUnit: val.workUnit, //工作单位的文字值
      phone: val.phone, //手机号
      idCard: val.idCard, //身份证号
      workIds: val.workIds, //工种 id  多个格式为：‘165,166,167’
      workVal: val.workVal, //工种的文字值  多个格式为：‘电工,电焊工,瓦工’
      enable: val.enable, //启用状态 0-未启用 1-已启用
      idCardImg: val.idCardImg, //身份证图片
      idCardImg1: val.idCardImg1, //身份证图片 正面
      idCardImg2: val.idCardImg2, //身份证图片 反面
      trainPic: val.trainPic, //培训证明证书照片
      avatar: val.avatar, //个人照片
      jobNumber: val.jobNumber //个人编号
    }
  }
  return request({
    url: '/addOutsourcing',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getOutsourcingData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  // val.workId = undefined;
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId, //机构 id
      theid: val.theid, //id
      fullName: val.fullName, //姓名
      password: val.password, //登录密码
      headPortrait: val.headPortrait, //头像照片
      genderId: val.genderId, //性别 id 1-男 2-女
      genderVal: val.genderVal, //性别的文字值
      unitId: val.unitId, //工作单位 id
      workUnit: val.workUnit, //工作单位的文字值
      phone: val.phone, //手机号
      idCard: val.idCard, //身份证号
      workIds: val.workIds, //工种 id  多个格式为：‘165,166,167’
      workVal: val.workVal, //工种的文字值  多个格式为：‘电工,电焊工,瓦工’
      enable: val.enable, //启用状态 0-未启用 1-已启用
      idCardImg: val.idCardImg, //身份证图片
      idCardImg1: val.idCardImg1, //身份证图片 正面
      idCardImg2: val.idCardImg2, //身份证图片 反面
      trainPic: val.trainPic, //培训证明证书照片
      avatar: val.avatar, //个人照片
      jobNumber: val.jobNumber //个人编号
    }
  }
  return request({
    url: '/updateOutsourcing',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delOutsourcing',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleOutsourcing',
    method: 'post',
    data: data
  })
}

// 状态启用
export function EnableStaff(theid, enable) {
  const data = {
    projectContent: {
      theid,
      enable
    }
  }
  return request({
    url: '/changeEnableOutsourcing',
    method: 'post',
    data: data
  })
}

// 下拉框 工种、岗位
export function getSelect() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getOutsourcingComboBox',
    method: 'post',
    data: data
  })
}

// 下拉框 证书
export function getCertificate() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getCertificateComboBox',
    method: 'post',
    data: data
  })
}

// 批量修改工种  
/**
projectContent:{
  'theid': 165, //id  修改多个格式为：‘165,166,167’
  'workIds': '156', //工种 id  多个格式为：‘165,166,167’
  'workVal': '电工', //工种的文字值  多个格式为：‘电工,电焊工,瓦工’
}
 */

export function changeWorkType(val) {
  const data = {
    projectContent: {
      theid: val.theid,
      workIds: val.workIds,
      workVal: val.workVal,
    }
  }
  // theid
  return request({
    url: '/changeWorkTypeOutsourcing',
    method: 'post',
    data: data
  })
}